package TCP_chat;
//package com;

import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

public class HaoServer {
	public static void main(String[] args) throws Exception{
		ServerSocket svr=null;
		
		try{
			//0. Server lang nghe cong 9999
			svr=new ServerSocket(9999);
			System.out.println("dang lang nghe client...");
			//2.1 nhan yeu cau tu client
			Socket soc=svr.accept();
			//get request. test based data: Scanner;object
			Scanner in=new Scanner(soc.getInputStream());
			String request=in.nextLine();
			//3. xu ly yeu cau
			String response="FROM SERVER: "+request.toUpperCase();
			System.out.println("dang xy ly yeu cau...");
			//4. server send response to client
			PrintWriter out=new PrintWriter(soc.getOutputStream(), true);
			out.println(response);
			
			in.close();out.close();
		}
		catch (Exception e){
			e.getStackTrace();
		}
		finally{
			if(svr!=null) svr.close();
		}
	}
	
}
